import pygame
from pygame.locals import *
import sys

class Instructions():
	def __init__(self,screen,bg,font1,font2,controls,colours,names):

                self.screen=screen
                self.bg=bg

                title_game_label = font2.render("DiDiBall", 1, (255,255,0))

                title= "Instructions"
                title_label = font1.render(title, 1, (35,35,255))
                screen.blit( bg, (0,0))
                width= screen.get_rect().width

                self.title_game_left=width*0.5-title_game_label.get_width()*0.5
                screen.blit(title_game_label,(self.title_game_left,200))
                self.title_left=width*0.5-title_label.get_width()*0.5
                screen.blit(title_label,(self.title_left,300))
                #keys
                self.show_controls(controls[0],font1,font2,colours[0],names[0],100+width/2)
                self.show_controls(controls[1],font1,font2,colours[1],names[1],200)

        def show_controls(self,controls,font1,font2,colour,name,left):
                yoffset=340
                label=font1.render("{0}".format(name),1,colour)
                self.screen.blit(label,(left,yoffset))
                if controls == None:
                   label=font1.render("CPU",1,colour)
                   self.screen.blit(label,(left,yoffset+40))
                else:
                    iter=0
                    for item in controls[0]:
                        label = font1.render(item,1,(35,35,35))
                        self.screen.blit(label,(left,yoffset+(iter+1)*40))
                        label = font1.render(controls[1][iter],1,colour)
                        self.screen.blit(label,(left+100,yoffset+(iter+1)*40))
                        iter+=1

                pygame.display.update()

        def loop(self):
                while 1:
                    for event in pygame.event.get():
                        if event.type == QUIT:
                            sys.exit()
                      
                    keys = pygame.key.get_pressed()
         
                    if keys[ K_RETURN]:
                        return True
